{extend name="platform/base" /}
{block name="resources"/}
<script type="text/javascript" charset="utf-8" src="ADMIN_JS/ueditor/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="ADMIN_JS/ueditor/ueditor.all.common.js"></script>
{/block}
{block name="main"}
<section class="panel panel-default">
	<header class="panel-heading font-bold"> 编辑帮助内容</header>
	<div class="panel-body">
		<form class="form-horizontal" id="form" name="form" onsubmit="">
		   <input type="hidden" value="{$result.id}" id="article_id"/>
			<div class="form-group">
				<label class="col-sm-2 control-label"><span style="color:red;line-height:30px;">*</span>文章标题</label>
				<div class="col-md-6">
					<input type="text" class="form-control" id="title" value="{$document_detail.title}">
				</div>
			</div>
	
<!-- 			<div class="line line-dashed line-lg pull-in"></div> -->
			<!-- 上传图片 -->
			<div class="form-group" style="display:none;">
                                   <label class="col-sm-2 control-label">标题图片</label>
                                   <div class="col-sm-4">
                                   	<p><img id="imgLogo" src="__UPLOAD__/{$result.image}" class="imglogo"/></p>
                                   	<a href="javascript:void(0);" style="display:block;position:relative;z-index:1;">
                                   		<span style="width: 97px;height: 34px;position: absolute;left: 0;top: 0;z-index: 2;cursor: pointer;"> 
                                   		<input hidefocus="true" size="1" class="input-file" name="file_upload"
					id="uploadImg" nc_type="change_store_label" type="file" style="width: 97px;height: 34px;padding: 0;margin: 0;border: none 0;opacity: 0;filter: alpha(opacity = 0);cursor: pointer;"
					onchange="imgUpload(this);"> 
					<input type="hidden" id="Logo" value="{$result.image}" />
				</span>
				<a class="btn btn-default"><i class="fa fa-cloud-upload text"></i><span class="text">上传图片</span></a>
		            	</a>
                                   </div>
            </div>
		
<!-- 			<div class="line line-dashed line-lg pull-in"></div> -->
				<div class="form-group" style="display:none;">
				<label class="col-sm-2 control-label">文章来源链接</label>
				<div class="col-md-4">
					<input type="text" class="form-control" id="url" value="{$result.link_url}">
				</div>
			</div>
			<div class="line line-dashed line-lg pull-in"></div>
			<div class="form-group">
				<label class="col-sm-2 control-label">所属分类</label>
				<div class="col-sm-4">
					<select id="class_id" name="account" class="form-control m-b">
						{volist name="help_class_list" id="v"}
							<option value="{$v['class_id']}" {if condition="$document_detail.class_id == $v['class_id']"}selected{/if}>{$v['class_name']}</option>
						{/volist} 
					</select>
				</div>
		
			</div>
			<div class="line line-dashed line-lg pull-in"></div>
			<div class="form-group">
				<label class="col-sm-2 control-label"><span style="color:red;line-height:30px;">*</span>文章内容</label>
				<div class="col-sm-8">
					<script id="editor" type="text/plain" style="width: 80%; height: 200px;">{$document_detail.content}</script>
				</div>
			</div>
			<!-- 书签 -->
<!-- 			<div class="line line-dashed line-lg pull-in"></div> -->
				<div class="form-group" style="display:none;">
				<label class="col-sm-2 control-label">文章内容</label>
				      <div class="col-sm-8">
	                         <div class="btn-toolbar m-b-sm btn-editor" data-role="editor-toolbar" data-target="#editor">
	                             <div class="btn-group"> <a class="btn btn-default btn-sm dropdown-toggle" data-toggle="dropdown" title="Font"><i class="fa fa-font"></i><b class="caret"></b></a>
	                                 <ul class="dropdown-menu">
	                                 </ul>
	                             </div>
	                             <div class="btn-group"> <a class="btn btn-default btn-sm dropdown-toggle" data-toggle="dropdown" title="Font Size"><i class="fa fa-text-height"></i>&nbsp;<b class="caret"></b></a>
	                                 <ul class="dropdown-menu">
	                                     <li>
	                                         <a data-edit="fontSize 5">
	                                             <font size="5">Huge</font>
	                                         </a>
	                                     </li>
	                                     <li>
	                                         <a data-edit="fontSize 3">
	                                             <font size="3">Normal</font>
	                                         </a>
	                                     </li>
	                                     <li>
	                                         <a data-edit="fontSize 1">
	                                             <font size="1">Small</font>
	                                         </a>
	                                     </li>
	                                 </ul>
	                             </div>
	                             <div class="btn-group"> <a class="btn btn-default btn-sm" data-edit="bold" title="Bold (Ctrl/Cmd+B)"><i class="fa fa-bold"></i></a> <a class="btn btn-default btn-sm" data-edit="italic" title="Italic (Ctrl/Cmd+I)"><i class="fa fa-italic"></i></a> <a class="btn btn-default btn-sm" data-edit="strikethrough" title="Strikethrough"><i class="fa fa-strikethrough"></i></a> <a class="btn btn-default btn-sm" data-edit="underline" title="Underline (Ctrl/Cmd+U)"><i class="fa fa-underline"></i></a> </div>
	                             <div class="btn-group"> <a class="btn btn-default btn-sm" data-edit="insertunorderedlist" title="Bullet list"><i class="fa fa-list-ul"></i></a> <a class="btn btn-default btn-sm" data-edit="insertorderedlist" title="Number list"><i class="fa fa-list-ol"></i></a> <a class="btn btn-default btn-sm" data-edit="outdent" title="Reduce indent (Shift+Tab)"><i class="fa fa-dedent"></i></a> <a class="btn btn-default btn-sm" data-edit="indent" title="Indent (Tab)"><i class="fa fa-indent"></i></a> </div>
	                             <div class="btn-group"> <a class="btn btn-default btn-sm" data-edit="justifyleft" title="Align Left (Ctrl/Cmd+L)"><i class="fa fa-align-left"></i></a> <a class="btn btn-default btn-sm" data-edit="justifycenter" title="Center (Ctrl/Cmd+E)"><i class="fa fa-align-center"></i></a> <a class="btn btn-default btn-sm" data-edit="justifyright" title="Align Right (Ctrl/Cmd+R)"><i class="fa fa-align-right"></i></a> <a class="btn btn-default btn-sm" data-edit="justifyfull" title="Justify (Ctrl/Cmd+J)"><i class="fa fa-align-justify"></i></a> </div>
	                             <div class="btn-group"> <a class="btn btn-default btn-sm dropdown-toggle" data-toggle="dropdown" title="Hyperlink"><i class="fa fa-link"></i></a>
	                                 <div class="dropdown-menu">
	                                     <div class="input-group m-l-xs m-r-xs">
	                                         <input class="form-control input-sm" placeholder="URL" type="text" data-edit="createLink">
	                                         <div class="input-group-btn">
	                                             <button class="btn btn-default btn-sm" type="button">Add</button>
	                                         </div>
	                                     </div>
	                                 </div>
	                                 <a class="btn btn-default btn-sm" data-edit="unlink" title="Remove Hyperlink"><i class="fa fa-cut"></i></a> </div>
	                             <div class="btn-group"> <a class="btn btn-default btn-sm" title="Insert picture (or just drag & drop)" id="pictureBtn"><i class="fa fa-picture-o"></i></a>
	                                 <input type="file" data-role="magic-overlay" data-target="#pictureBtn" data-edit="insertImage" />
	                             </div>
	                             <div class="btn-group"> <a class="btn btn-default btn-sm" data-edit="undo" title="Undo (Ctrl/Cmd+Z)"><i class="fa fa-undo"></i></a> <a class="btn btn-default btn-sm" data-edit="redo" title="Redo (Ctrl/Cmd+Y)"><i class="fa fa-repeat"></i></a> </div>
	                             <input type="text" class="form-control-trans pull-left" data-edit="inserttext" id="voiceBtn" x-webkit-speech="" style="width:25px;height:28px;">
	                         </div>
	                         <div id="editor" class="form-control" style="overflow:scroll;height:150px;max-height:150px">{$result.content}</div>
	                     </div>
	                    
			    </div>
			<div class="line line-dashed line-lg pull-in"></div>
			<div class="form-group">
				<label class="col-sm-2 control-label">文章排序</label>
				<div class="col-md-1">
					<input type="text" class="form-control" id="sort"  value="{$document_detail.sort}">
				</div>
			</div>
			<input type="hidden" value="{$id}" id="document_id" />
<!-- 			<input type="hidden" value="{$document_detail.content}" id="content" /> -->
			<div class="line line-dashed line-lg pull-in"></div>
			<div class="form-group">
				<div class="col-sm-4 col-sm-offset-2">
					<a href="javascript:void(0);" onclick="setConfigAjax()" class="btn btn-primary">修改文章</a>
				</div>
			</div>
		</form>
	</div>
</section>
   
{/block} 
{block name="script"}
<!-- <script src="ADMIN_JS/ajax_file_upload.js" type="text/javascript"></script>
<script src="__STATIC__/js/file_upload.js" type="text/javascript"></script>
{include file="platform/openDialog" /} -->
  <script type="text/javascript">
 
  var ue = UE.getEditor('editor',{
		toolbars : [
		            [ 'source', // 源代码
			'bold', // 加粗
			'italic', // 斜体
			'underline', // 下划线
			'strikethrough', // 删除线
			'forecolor', // 字体颜色
			'backcolor', // 背景色
			'fontfamily', // 字体
			'fontsize', // 字号
			'paragraph', // 段落格式
			'justifyleft', // 居左对齐
			'justifycenter', // 居中对齐
			'justifyright', // 居右对齐
			'superscript', // 上标
			'blockquote', // 引用
			'selectall', // 全选
			'preview', // 预览
			'removeformat', // 清除格式
			'inserttable', // 插入表格
			'unlink', // 取消链接
			'insertrow', // 前插入行
			'insertcol', // 前插入列
			'mergeright', // 右合并单元格
			'mergedown', // 下合并单元格
			'deleterow', // 删除行
			'deletecol', // 删除列
			'splittorows', // 拆分成行
			'splittocols', // 拆分成列
			'splittocells', // 完全拆分单元格
			'deletecaption', // 删除表格标题
			'inserttitle', // 插入标题
			'mergecells', // 合并多个单元格
			'deletetable', // 删除表格
			'cleardoc', // 清空文档
			 'simpleupload', // 单图上传
			'insertimage', // 多图上传
			'link', // 超链接
			'emotion', // 表情
			'insertorderedlist', // 有序列表
			'insertunorderedlist', // 无序列表
			'fullscreen', // 全屏
			'directionalityltr', // 从左向右输入
			'directionalityrtl', // 从右向左输入
			'imagenone', // 默认
			'imageleft', // 左浮动
			'imageright', // 右浮动
			// 'attachment', // 附件
			'imagecenter', // 居中
			'lineheight', // 行间距
			'customstyle', // 自定义标题
			]]
	});
	$(function(){
		
		UE.getEditor('editor').addListener( 'ready', function() {
			if($("#content").val()){
				UE.getEditor('editor').setContent($("#content").val());
			}
		} );
	})
		function setConfigAjax() {
			var id = $("#document_id").val();
			var title = $("#title").val();
			var class_id = $("#class_id").val();
			var link_url = $("#link_url").val();
			var image = $("#logo").val();
			var content = UE.getEditor('editor').getContent();
			var sort = $("#sort").val();
			if(title == ""){
				showMessage('error', "请输入标题");
				return;
			}
			if(content == ""){
				showMessage('error', "请输入内容");
				return;
			}
			$.ajax({
				type : "post",
				url : "PLATFORM_MAIN/config/updatedocument",
				data : {
					'id' : id,
					'title' : title,
					'class_id' : class_id,
					'link_url' : link_url,
					'content' : content,
					'image' : image,
					'sort' : sort
				},
				success : function(data) {
					if (data["code"] > 0) {
						showMessage('success', data["message"]);
						location.href="PLATFORM_MAIN/config/helpdocument";
					} else {
						showMessage('error', data["message"]);
					}
				}
			});
		}
     /**
 	 *图片上传
 	 */
 	function imgUpload(event) {
 		var fileid = $(event).attr("id");
 		var data = { 'file_path' : UPLOADCOMMON };
 		uploadFile(fileid,data,function(res){
 			if(res.code){
 				$("#imglogo").attr("src","__UPLOAD__/"+res.data);
 				$("#logo").val(res.data);
 				showTip(res.message,"success");
 			}else{
 				showTip(res.message,"error");
 			}
 		});
 	}

  </script>
  
{/block}